package com.xdf.docmanagementsystem.common.util;

import org.dozer.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: doc-management-system
 * @description: 对象操作
 * @author: Zhang
 * @create: 2020-06-22 09:23
 **/
public class ObjectUtil {

    /**
     * 批量转换
     *
     * @param mapper
     * @param sourceList
     * @param v
     * @param <T>
     * @param <V>
     * @return
     */
    public static <T, V> List<V> conventList(final Mapper mapper, List<T> sourceList, Class<V> v) {
        List<V> targetList = new ArrayList<>();
        try {
            if (sourceList != null && sourceList.size() > 0)
                for (T item : sourceList) {
                    targetList.add(mapper.map(item, v));
                }
        } catch (Exception e) {
            return targetList;
        }
        return targetList;
    }
}
